/**
 * Created by Yu Jin Xian on 2016/12/7.
 */
function newObject() {
    var person = new Object();

    function create() {
        var person = new Object();
        person.name = 'Nicholas';
        person.age = 29;
    }

    function literals() {
        var person = {
            name: 'Nicholas',
            age: 29
        };
    }

    function or() {
        var person = {
            'name': 'Nicholas',
            'age': 29,
            5: true
        }
    }

    function youCanAlso() {
        var person = {};        // 与 new Objects() 相同
        person.name = 'Nicholas';
        person.age = 29;
    }

    function displayInfo(args) {
        var output = '';
        if (typeof args.name == 'string') {
            output += 'Name: ' + args.name + '\n';
        }
        if (typeof args.age == 'number') {
            output += 'Age: ' + args.age + '\n';
        }
        alert(output);
    }

    displayInfo({name: 'Nicholas', age: 29});
    displayInfo({name: 'Greg'});

    function getProperty() {
        var person = {};
        person.name = 'Nicholas';
        alert(person['name']);  // "Nicholas"
        alert(person.name);     // "Nicholas"

        var propertyName = 'name';
        alert(person[propertyName]);

        person['first name'] = 'Nicholas';
    }
}